define(function () {
    return function (pane) {
        /**
         * 导航
         */
        {
            pane.html(utils.getHtml('default_table'));

            utils.addFilterGroupbtn(pane, {
                text: '全部状态',
                name: 'payStatus',
                filters: [{text: '订单付款', value: '订单付款'}, {text: '订单收货', value: '订单收货'}, {
                    text: '订单结算',
                    value: '订单结算'
                }, {text: '订单失效', value: '订单失效'}]
            });

            utils.addFilterGroupbtn(pane, {
                text: '全部',
                name: 'has_settle_id',
                filters: [{value: "0", text: "未结算"}, {value: "1", text: "已结算"}]
            });
        }

        /**
         * 统计
         */
        {
            var analyse = function () {
                // adminApi('orders_analyse').then(function (rows) {
                //     console.log(rows);
                // });
            }
            analyse();
        }

        //初始化工具
        utils.addTools(pane, [
            {className: 'refresh-btn', icon: 'fa-refresh', text: '刷新'}
        ]);
        $(pane).on('click', '.refresh-btn', function () {
            if (table) {
                table.api().draw();
                analyse();
            }
        });

        //初始化表格
        var table = utils.dataTable(pane, {
            columns_arrays: [
                ["id", "#"],
                ["partner_id", "合伙人", false, function (i, t, row) {
                    var user = row.partner;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>';
                }, 'filterable'],
                ["agency_id", "代理", false, function (i, t, row) {
                    var user = row.agency;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>';
                }, 'filterable'],
                ["user_id", "用户", false, function (i, t, row) {
                    var user = row.user;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>' + '<div>订单数: ' + user.order_count + '/' + user.finish_count + '/' + user.sham_count + '&nbsp;&nbsp;金额: ' + user.amount + '/' + user.frozen + '</div>';
                }, 'filterable'],
                ["pictUrl", "图片", false, utils.imageRender('')],
                ["auctionId", "商品名", false, function (i, t, row) {
                    return '<div style="max-width: 160px;">' + (row.auctionTitle || '') + '</div>';
                }, 'filterable'],
                ["exNickName", "店铺", false, function (i, t, row) {
                    return '<div style="max-width: 160px;">' + (row.exShopTitle || '') + '</div>';
                }, 'filterable'],
                ["payStatus", "状态", false],
                ["id", "返现状态", false, function (i, t, row) {
                    return '<div style="min-width: 150px;"><div>' + row.taobaoTradeParentId + '</div><div>付款金额:' + row.totalAlipayFeeString + '</div>' +
                        '<div>预估收入:￥' + row.feeString + '/' + row.discountAndSubsidyToString + '%</div>' +
                        '<div>返现状态:' + row.amount_status + '</div>' +
                        '<div>返现金额:<span class="badge" style="background-color: #00a65a!important; cursor: pointer;">￥' + (row.pay_amount || 0) + '</span></div>' +
                        '<div>邀请返现:<span class="badge" style="background-color: #f39c12!important; cursor: pointer;">￥' + (row.inviter_pay_amount || 0) + '</span></div>' +
                        '<div>代理收入:<span class="badge" style="background-color: #3c8dbc!important; cursor: pointer;">￥' + (row.agency_amount || 0 ) + '</span></div>' +
                        '<div>上级收入:<span class="badge" style="background-color: #3c8dbc!important; cursor: pointer;">￥' + (row.inviter_agency_amount || 0 ) + '</span></div>' +
                        '<div>预计收入:<span class="badge" style="background-color: #dd4b39!important; cursor: pointer;">￥' + (row.income || 0) + '</span></div></div>';
                }],
                ["mediumId", "媒体", false, function (i, t, row) {
                    return row.mediumName;
                }, 'filterable'],
                ["adPositionId", "广告位", false, function (i, t, row) {
                    return row.adPositionName;
                }, 'filterable'],
                ["agency_settle_id", "结算号", false, false, 'filterable'],
                ["clickTime", "点击时间", true, utils.dateTimeRender()],
                ["createTime", "下单时间", true, utils.dateTimeRender()],
                ["earningTime", "结算时间", true, utils.dateTimeRender()],
                ["created_at", "创建时间", false, utils.dateTimeRender()]
            ],
            sorting: [[0, 'desc']],
            fnServerData: function (paramData) {
                return adminApi('orders_browse', paramData);
            }
        });
    }
});